home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmMD_My_Modeless.p < prev    next >
Text File  |  1994-01-16  |  11KB  |  313 lines

  1.  
  2. Unit mmMD_My_Modeless;
  3. {  mmMD_My_Modeless                                 Handle this dialog }
  4. {  Copyright © 1994 George R. Cossey }
  5.  
  6. {    File name:  mmMD_My_Modeless
  7.     Function:  Handle this modeless dialog.
  8.  
  9.     This dialog is called when:
  10.  
  11.     History: 1/16/94 Original by George Cossey
  12.  
  13. }
  14.  
  15. { ======================================================= }
  16. { ======================================================= }
  17.  
  18. interface
  19.  
  20.     uses
  21.         Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
  22.         mmPA_My_Alert,
  23.         {}
  24.         mmD_My_Modal,
  25.         {}
  26.         UMy_Modeless;
  27.  
  28.  
  29. procedure Init_My_Modeless;
  30. procedure Moved_My_Modeless(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  31. procedure Update_My_Modeless(theWindow:WindowPtr);
  32. procedure Open_My_Modeless;
  33. procedure Close_My_Modeless(theWindow:WindowPtr);
  34. procedure Do_My_Modeless(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  35.  
  36. { ======================================================= }
  37. { ======================================================= }
  38.  
  39. implementation
  40.  
  41. { ======================================================= }
  42. { ======================================================= }
  43.  
  44. { Routine: Init_My_Modeless }
  45. { Purpose: This procedures purpose is to set the window pointer to nil, }
  46. { this is used to tell the other routines }
  47.  
  48. procedure Init_My_Modeless;
  49. var
  50.     tempRect:Rect;                                    { Temporary rectangle }
  51.     DType:integer;                                    { Type of dialog item }
  52.     Index:integer;                                    { For looping }
  53.     DItem:Handle;                                    { Handle to the dialog item }
  54.     CItem, CTempItem:ControlHandle;                    { Control handle }
  55.     sTemp:Str255;                                    { Get text entered, temp holding }
  56.     itemHit:integer;                                { Get selection }
  57.     temp:integer;                                    { Get selection, temp holding }
  58.  
  59.  
  60. begin
  61. Rec_My_Modeless.theDialog := nil;                    { Initialize to say that the dialog is not yet active }
  62.  
  63. Rec_My_Modeless.Enable_OK5 := true;            { Button }
  64. Rec_My_Modeless.Enable_Cancel4 := true;            { Button }
  65. Rec_My_Modeless.Enable_My_Scroll_bar := true;            { ScrollBar }
  66. Rec_My_Modeless.Value_My_Scroll_bar := 1;
  67. Rec_My_Modeless.Enable_The_Icon := true;            { Icon button }
  68. Rec_My_Modeless.Enable_The_Sicn := true;            { Sicn button }
  69. Rec_My_Modeless.Enable_Tool_palette := true;            { Palette }
  70. Rec_My_Modeless.Value_Tool_palette := 0;
  71.  
  72. U_Init_My_Modeless;                            { Call the user init routine }
  73. end;
  74.  
  75. { ======================================================= }
  76.  
  77. { Routine: Moved_My_Modeless }
  78. { Purpose: We were moved, possibly to another screen and screen depth }
  79.  
  80. procedure Moved_My_Modeless(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  81. var
  82.     SavePort:WindowPtr;                                { Place to save the last port }
  83.  
  84.  
  85. begin
  86. if (Rec_My_Modeless.theDialog = theWindow)    then            { Only do if the window is us }
  87.     begin
  88.     GetPort(SavePort);                            { Save the current port }
  89.     SetPort(theWindow);                            { Set the port to my window }
  90.  
  91.     U_Moved_My_Modeless(theWindow,OldRect);    { Call user routine when we are moved }
  92.     SetPort(SavePort);                                { Restore the old port }
  93.     end;                                            { End of IF }
  94. end;
  95.  
  96. { ======================================================= }
  97.  
  98. { Routine: Update_My_Modeless }
  99. { Purpose: This procedures purpose is to refresh this window, update it, }
  100. { when we are uncovered by another window.  }
  101.  
  102. procedure Update_My_Modeless(theWindow:WindowPtr);
  103. var
  104.     SavedPort:GrafPtr;                                { Save the current port so we can restore to it }
  105.     tempRect:Rect;                                    { Temporary rectangle variable }
  106.     rTempRect:Rect;                                    { Temporary rectangle variable }
  107.     DType:integer;                                    { Type of dialog item }
  108.     DItem:Handle;                                    { Handle to the dialog item }
  109.     CItem:ControlHandle;                            { Control handle }
  110.     Saved_ForeColor:RGBColor;                        { Place to save colors }
  111.     Saved_BackColor:RGBColor;                        { Place to save colors }
  112.     DrawingColor:RGBColor;                            { Place to make colors }
  113.  
  114.  
  115. begin
  116. if ((Rec_My_Modeless.theDialog <> nil) and (theWindow = Rec_My_Modeless.theDialog)) then{ Only do if we are the window to update }
  117.     begin
  118.     GetPort(SavedPort);                            { Get the current port }
  119.     SetPort(theWindow);                            { Point to our port for drawing in our window }
  120.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  121.         begin
  122.         GetForeColor(Saved_ForeColor);            { Save the fore color }
  123.         GetBackColor(Saved_BackColor);            { Save the back color }
  124.  
  125.         RGBForeColor(Black_ForeColor);            { Set the fore color to Black }
  126.         RGBBackColor(White_BackColor);            { Set the back color to White }
  127.         end;                                        { End of IF }
  128.  
  129.     { This is the default selection, when RETURN is pressed. }
  130.     HiliteDefaultButton(theWindow,ResD_OK5);
  131.  
  132.     { Draw a line, Drawn line }
  133.     PenSize(1,1);
  134.     MoveTo(110,110);        { Horz,vert, Move to starting position }
  135.     LineTo(284,110);    { Horz,vert, Draw to the ending position }
  136.     PenSize(1,1);
  137.  
  138.     TextSize(12);
  139.     TextFont(systemFont);                                { Select the Font that we want }
  140.     TextFace([]);                                        { Select the style that we want }
  141.  
  142.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  143.         begin
  144.         RGBForeColor(Saved_ForeColor);            { Restore the fore color }
  145.         RGBBackColor(Saved_BackColor);            { Restore the back color }
  146.         end;
  147.  
  148.     U_Update_My_Modeless(theWindow);            { Call the user update routine }
  149.  
  150.     DrawDialog(theWindow);                            { Draw the rest of the controls }
  151.     SetPort(SavedPort);                            { Restore the port that we saved at the start }
  152.     end;
  153. end;
  154.  
  155. { ======================================================= }
  156.  
  157. { Routine: Open_My_Modeless }
  158. { Purpose: This procedures purpose is to open this window and set all }
  159. { of the initial conditions, such as default edit text. }
  160.  
  161. procedure Open_My_Modeless;
  162. var
  163.     ThisEditText:TEHandle; 
  164.     TheDialogPtr:DialogPeek;
  165.     tempRect:Rect;                                { Temporary rectangle variable }
  166.     DType:integer;                                { Type of dialog item }
  167.     DItem:Handle;                                { Handle to the dialog item }
  168.     CItem:ControlHandle;                        { Control handle }
  169.     LTemp,LTemp2,theLong:longint;                { Get selection, temp holding }
  170.  
  171.  
  172. begin
  173. if (Rec_My_Modeless.theDialog = NIL) then
  174.     begin
  175.     Rec_My_Modeless.theDialog := GetNewDialog(ResD_My_Modeless,NIL,WindowPtr(-1));{ Bring in the dialog resource }
  176.     SetPort(Rec_My_Modeless.theDialog);        { Prepare to add conditional text }
  177.  
  178.  
  179.  
  180.     { Button }
  181.     SetupNormalControl(Rec_My_Modeless.theDialog,ResD_OK5,Rec_My_Modeless.Enable_OK5,0);
  182.  
  183.     { Button }
  184.     SetupNormalControl(Rec_My_Modeless.theDialog,ResD_Cancel4,Rec_My_Modeless.Enable_Cancel4,0);
  185.  
  186.     { Draw a Hotspot or Rectangle }
  187.     SetupHotSpot(Rec_My_Modeless.theDialog,ResD_Message_on_rect,false,1,
  188.         1,sResD_Message_on_rect,Rec_My_Modeless.Enable_Message_on_rect);
  189.  
  190.     { Draw a Palette }
  191.     SetupPalette(Rec_My_Modeless.theDialog,ResD_Tool_palette,Rec_My_Modeless.Enable_Tool_palette,
  192.         3,3,ResD_N_Tool_palette,6);
  193.  
  194.     { Draw an Icon button }
  195.     SetupIconSicn(Rec_My_Modeless.theDialog,ResD_The_Icon,Rec_My_Modeless.Enable_The_Icon,
  196.         ResD_N_The_Icon,ResD_H_The_Icon);
  197.  
  198.     { Draw a Sicn }
  199.     SetupIconSicn(Rec_My_Modeless.theDialog,ResD_The_Sicn,Rec_My_Modeless.Enable_The_Sicn,
  200.         ResD_N_The_Sicn,ResD_H_The_Sicn);
  201.  
  202.     SetupTheItem(Rec_My_Modeless.theDialog,ResD_My_Scroll_bar,true,true,Rec_My_Modeless.Enable_My_Scroll_bar,true,tempRect,0,0);
  203.     SetupMinMaxValue(Rec_My_Modeless.theDialog,ResD_My_Scroll_bar,1,100,Rec_My_Modeless.Value_My_Scroll_bar);
  204.  
  205.  
  206.  
  207.     U_Setup_My_Modeless(Rec_My_Modeless.theDialog);{ Call the user Open procedure }
  208.  
  209.     ShowWindow(Rec_My_Modeless.theDialog);                { Open a dialog box }
  210.     SelectWindow(Rec_My_Modeless.theDialog);            { Lets see it }
  211.     end
  212. else
  213.     SelectWindow(Rec_My_Modeless.theDialog);        { Lets see it }
  214. end;
  215.  
  216. { ======================================================= }
  217.  
  218. { Routine: Close_My_Modeless }
  219. { Purpose: This procedures purpose is to close this window and clear }
  220. { the window pointer variable }
  221.  
  222. procedure Close_My_Modeless(theWindow:WindowPtr);
  223. var
  224.     tempRect:Rect;                                    { Temporary rectangle }
  225.     DType:integer;                                    { Type of dialog item }
  226.     DItem:Handle;                                    { Handle to the dialog item }
  227.  
  228.  
  229. begin
  230. if ((Rec_My_Modeless.theDialog <> NIL) and (theWindow = Rec_My_Modeless.theDialog)) then{ Only close if it is us and we were open }
  231.     begin
  232.     U_Close_My_Modeless(theWindow);            { Call the user close routine }
  233.  
  234.  
  235.     DisposDialog(theWindow);                        { Close on the screen and Flush the dialog out of memory }
  236.     Rec_My_Modeless.theDialog := nil;            { Make sure our other routines know that we are closed }
  237.     end;
  238. end;
  239.  
  240. { ======================================================= }
  241.  
  242. { Routine: Do_My_Modeless }
  243. { Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. }
  244. { This is the real meat of this unit and is where the code is for acting upon the users actions. }
  245.  
  246. procedure Do_My_Modeless(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  247. var
  248.     Index:integer;                                        { For looping }
  249.     myPt:Point;                                            { For the local mouse position }
  250.     DType:integer;                                        { Type of dialog item }
  251.     DItem:Handle;                                        { Handle to the dialog item }
  252.     tempRect:Rect;                                        { Temporary rectangle }
  253.     CItem:ControlHandle;                                { Control handle }
  254.     temp:integer;                                        { temp integer }
  255.     code:integer;                                        { temp integer }
  256.     theSelection:integer;                                { For Palettes }
  257.     DoubleClick:Boolean;                                { For sensing double clicks in a list }
  258.  
  259.  
  260. begin
  261. Rec_My_Modeless.ExitDialog := false;            { Do not close the dialog yet }
  262. if ((theEvent.what = mouseDown) and (Rec_My_Modeless.theDialog <> nil)) then
  263.     begin
  264.     SetPort(Rec_My_Modeless.theDialog);                    { Set the port to our dialog }
  265.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  266.     GlobalToLocal(myPt);                            { Change from global to local location }
  267.  
  268.     end;
  269.  
  270. if ((Rec_My_Modeless.theDialog <> nil) and (Rec_My_Modeless.theDialog = theWindow)) then
  271.     begin
  272.     CheckKeysInDialog(theWindow,DoubleClick,theEvent,itemHit);
  273.  
  274.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  275.     GlobalToLocal(myPt);                            { Change from global to local location }
  276.  
  277.     U_Hit_My_Modeless(theWindow,itemHit,Rec_My_Modeless.ExitDialog,theEvent);{ Give the user the itemhit }
  278.  
  279.     if (itemHit > 0) then                                { Skip if user set to zero }
  280.         begin
  281.         GetDItem(theWindow,itemHit,DType,DItem,tempRect);{ Get which item was pressed }
  282.         CItem := ControlHandle(DItem);                { Change the pointer for getting to the control }
  283.         end;
  284.     
  285.     { Handle it real time }
  286.     if (itemHit = ResD_OK5) then                { Handle the Button being pressed }
  287.         begin
  288.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Modeless,0,0,nil);    { Close this modeless dialog }
  289.         Rec_My_Modeless.ExitDialog := true;        { Close this dialog, exit }
  290.         end;
  291.  
  292.     if (itemHit = ResD_Cancel4) then                { Handle the Button being pressed }
  293.         begin
  294.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Modeless,0,0,nil);    { Close this modeless dialog }
  295.         Rec_My_Modeless.ExitDialog := true;        { Close this dialog, exit }
  296.         end;
  297.  
  298.     { Palette }
  299.  
  300.  
  301.     end;
  302.  
  303. if (Rec_My_Modeless.ExitDialog) then                { Do the close of the dialog }
  304.     begin
  305.     Close_My_Modeless(Rec_My_Modeless.theDialog);
  306.     Rec_My_Modeless.theDialog := nil;                    { Clear it for future checks }
  307.     end;
  308. end;
  309.  
  310. { ======================================================= }
  311. { ======================================================= }
  312. end.
  313.